package ldkxingzhe.l365calendar.fragment;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;

import ldkxingzhe.l365calendar.R;

/**
 * 日程描述的编辑界面
 * Created by ke on 16-1-30.
 */
public class ScheduleDescriptionFragment extends AllEditFragmentBase{
    @SuppressWarnings("unused")
    private static final String TAG = "ScheduleCategoryFragment";

    public static final String RESULT = "result";

    EditText editText;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View resultView = inflater.inflate(R.layout.fragment_schedule_description, container, false);
        editText = (EditText) resultView.findViewById(R.id.edit_text);
        editText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if(TextUtils.isEmpty(s)){
                    setIsChanged(false);
                }else{
                    setIsChanged(true);
                }
            }
        });
        return resultView;
    }

    @Override
    public void onSaveClick() {
        Intent resultIntent = new Intent();
        resultIntent.putExtra(RESULT, editText.getText().toString().trim());
        getActivity().setResult(Activity.RESULT_OK, resultIntent);
        getActivity().finish();
    }
}
